In PyBrain, networks are composed of Modules which are connected with Connections. You can think of a network as a directed acyclic graph, where the nodes are Modules and the edges are Connections. This makes PyBrain very flexible but it is also not necessary in all cases.

The buildNetwork Shortcut

Thus, there is a simple way to create networks, which is the buildNetwork shortcut:

{% highlight python %}

from pybrain.tools.shortcuts import buildNetwork net = buildNetwork(2, 3, 1)

{% endhighlight %}

This call returns a network that has two inputs, three hidden and a single output neuron. In PyBrain, these layers are Module objects and they are already connected with FullConnection objects.

The Source Code

 

名次解释

RecurrentNetwork:递归网络 FeedForwardNetwork:前馈神经网络

关键点解释

1- def buildNetwork (layers, **options)中“”与“**”的意义。

 

当用func(1,2,3) 调用函数时,参数args就是元组(1,2,3)

 

当用func(a=1,b=2) 调用函数时,参数args将会是字典{'a':1,'b':2}

 

当调用func(1,2, a=1,b=2)时,打印:(1,2) {'a': 1, 'b': 2} 当调用func(a=1,b=2)时,打印:() {'a': 1, 'b': 2} 当调用func(1,2)时,打印:(1,2) {}

2 - def buildNetwork(*layers, **options): 中“”与“__”的意义。

_单下划线开头:弱“内部使用”标识,如:”from M import *”,将不导入所有以下划线开头的对象,包括包、模块、成员

单下划线结尾_:只是为了避免与python关键字的命名冲突

__双下划线开头:模块内的成员,表示私有成员,外部无法直接调用

双下划线开头双下划线结尾:指那些包含在用户无法控制的命名空间中的“魔术”对象或属性,如类成员的name、doc、init、import、file、等。推荐永远不要将这样的命名方式应用于自己的变量或函数。

步骤

S-1 Bind the right class to the Network name

 

S-2 Init network

 

S-3 Connections among layers

 

S-4 Recurrent connections

 

结语

PyBrain是Python实现人工神经网络的一个第三方库,可以利用其快速构建神经网络,本次只是展开其构建神经网络的大体步骤,接下来会对具体实现细节进行详细描述。

如果有相关问题,联系邮箱:misterrxzh@gmail.com,或直接联系我留言